// pages/order/editstudent/editstudent.js
const App = getApp()
let { AJAX,imgUrl} = require('../../../utils/util.js')


Page({

  /**
   * 页面的初始数据
   */
  data: {
    navH:"",
    index:'',
    customer:'',
    student:'',
    orderId:'',
    imgUrl: imgUrl
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData({
      navH: App.globalData.navHeight,
      orderId: options.id,
      index:options.index,
      customer: JSON.parse(wx.getStorageSync('CUSTOMERS')),
      "student": JSON.parse(wx.getStorageSync('CUSTOMERS'))[options.index],
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },
  inputInfo(e) {
    let _type = e.currentTarget.dataset.type
    let _data = this.data.student
    _data[_type] = e.detail.value
    this.setData({
      'student': _data
    })
  },
  selectSex(e) {
    let _val = e.currentTarget.dataset.val
    this.setData({
      'student.sex': _val
    })
  },
  
  sureStudent(){
    let vm=this
    let _data = vm.data.customer
    _data.splice(1,0,vm.data.student)
    AJAX("order/update-customer","POST",{
      order_id: vm.data.orderId,
      customer:JSON.stringify(_data)
    }).then(res=>{
      wx.navigateBack()
    })
  }
})